﻿using System.Collections;

namespace Simple.Services;

public class QHSEOrganizationTreeNodeModel : QHSEOrganizationModel, ITreeNode
{
    /// <summary>
    /// 主键
    /// </summary>
    public new string? Id { get; set; }

    /// <summary>
    /// 父级Id
    /// </summary>
    public string? ParentId { get; set; }

    public List<QHSEOrganizationTreeNodeModel> Children { get; set; } = new List<QHSEOrganizationTreeNodeModel>();

    public void SetChildren(IList children)
    {
        var nodes = children as List<QHSEOrganizationTreeNodeModel>;
        Children = nodes != null ? nodes : new List<QHSEOrganizationTreeNodeModel>();
    }

    public static TreeBuilder<QHSEOrganizationTreeNodeModel> CreateBuilder(List<QHSEOrganizationTreeNodeModel> nodes, string rootId)
    {
        return new TreeBuilder<QHSEOrganizationTreeNodeModel>(nodes, rootId);
    }

    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<QHSESysOrganization, QHSEOrganizationTreeNodeModel>()
            .ForMember(d => d.Id, options => options.MapFrom(s => s.OrganizationId));

        profile.CreateMap<QHSEOrganizationTreeNodeModel, QHSESysOrganization>()
            .ForMember(d => d.OrganizationId, options => options.MapFrom(s => s.Id));
    }
}
